/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package db;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Jayson Kiong
 */
public class SaveSoaServlet extends HttpServlet {
    int loanno=0;
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
       Connection con = DBConnector.connect();
        try{
            int clientid = Integer.parseInt(request.getParameter("clientid"));
            String duedate = request.getParameter("soaduedate");
            float collection = Float.parseFloat(request.getParameter("collection"));
            String startdate = request.getParameter("startdate");
            float monthly = Float.parseFloat(request.getParameter("monthly"));
            float amountdue = Float.parseFloat(request.getParameter("amountdue"));
            float comakerpay = Float.parseFloat(request.getParameter("comakerpay"));
            float fc = Float.parseFloat(request.getParameter("fc"));
            float cashpay = Float.parseFloat(request.getParameter("cashpay"));
            float refund = Float.parseFloat(request.getParameter("refund"));
            float balance = Float.parseFloat(request.getParameter("balance"));
            float fcpercent = Float.parseFloat(request.getParameter("fcpercent"));
            loanno = Integer.parseInt(request.getParameter("loanno"));
            

                String query = "insert into quicklenddb.soa "
                     + "(clientID, start_date, monthly, duedate, amountdue, collection, comakerpay, fc, cashpay, refund, balance, fc_percent)"
                     + " values(?,?,?,?,?,?,?,?,?,?,?,?)";
                PreparedStatement ps = con.prepareStatement(query);
                ps.setInt(1,clientid);
                ps.setString(2,startdate);
                ps.setFloat(3,monthly);
                ps.setString(4,duedate);
                ps.setFloat(5,amountdue);
                ps.setFloat(6,collection);
                ps.setFloat(7,comakerpay);
                ps.setFloat(8,fc);
                ps.setFloat(9,cashpay);
                ps.setFloat(10,refund);
                ps.setFloat(11,balance);
                ps.setFloat(12,fcpercent);
                ps.executeUpdate();
            
            
        }catch(Exception e){
            System.out.println(e);
        }
        response.sendRedirect("SelectLoanServlet?loanno="+loanno);
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        
        
}
    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
